package org.uim.cricket.entities.persist.impl;

import org.uim.cricket.entities.bowling.BowlerStatistics;
import org.uim.cricket.entities.persist.CricketEntityPersistable;

public class XMLBowlerStatisticsPersist implements CricketEntityPersistable<BowlerStatistics> {

	private String tagName = "Stats";
	
	@Override
	public String doPersist(BowlerStatistics object) {
		if (object == null) return "";
		StringBuilder sb = new StringBuilder();

		if (tagName.length() > 0) sb.append("<").append(tagName);

		sb.append(" overs=\"").append(object.getOvers()).append("\"");
		sb.append(" maidnes=\"").append(object.getMaidnes()).append("\"");
		sb.append(" runs=\"").append(object.getRuns()).append("\"");
		sb.append(" wickets=\"").append(object.getWickets()).append("\"");
		if (object.getNoballs() > 0) {
			sb.append(" noballs=\"").append(object.getNoballs()).append("\"");
		}
		if (object.getWides() > 0) {
			sb.append(" wides=\"").append(object.getWides()).append("\"");
		}

		if (tagName.length() > 0) sb.append(" />");
		return sb.toString();
	}

}
